<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>WebSocket 聊天</title>
</head>
<body>
<h1>WebSocket 聊天</h1>

<input id="message" type="text">
<button onclick="send()">发送</button>
<div id="messages"></div>

<script>
    const ws = new WebSocket("ws://localhost:9090/chat");

    ws.onmessage = (event) => {
        document.getElementById("messages").innerHTML += event.data + "<br>";
    };
    function send() {
        const msg = document.getElementById("message").value;
        ws.send(msg);
        document.getElementById("message").value = "";
    }
</script>
</body>
</html>